<template>
  <div class="row">
    <div v-for="column in columlist" :key="column" class="col-4 mb-3">
      <div class="card h-100 shadow-sm">
        <div class="card-body text-center">
          <img
            :src="column.avatar"
            alt="正在加载中"
            class="rounded-circle border border-light w-25"
          />
          <h5 class="card-title">{{ column.title }}</h5>
          <p class="card-text">
            {{ column.description }}
          </p>
          <button class="btn btn-outline-primary">进入专栏</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, PropType } from 'vue'
export interface IColumnProps {
  id: number
  avatar?: string
  title: string
  description: string
}
export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<IColumnProps[]>,
      require: true
    }
  },
  setup(props) {
    console.log(props)
    const columlist = computed(() => {
      const list = props.list as IColumnProps[] // 类型断言
      return list.map((item) => {
        if (!item.avatar) {
          item.avatar = require('../assets/avatar.jpg')
        }
        return item
      })
    })
    return { columlist }
  }
})
</script>
<style scoped>
p {
  text-align: left;
}
</style>
